package org.dochandler.esfinge.guardian.authorizer;

import org.dochandler.service.domain.Officer;
import org.dochandler.service.domain.annotation.AboveOfficerOnly;
import org.dochandler.service.domain.constants.Constants;
import org.esfinge.guardian.authorizer.Authorizer;
import org.esfinge.guardian.context.AuthorizationContext;

public class AboveOfficerOnlyAuthorizer implements Authorizer<AboveOfficerOnly>{

	@Override
	public Boolean authorize(AuthorizationContext context, AboveOfficerOnly securityAnnotation) {
		
		Officer subject = context.getSubject().get(Constants.OFFICER.val(), Officer.class);
		
		Officer creator = context.getSubject().get(Constants.CREATOR.val(), Officer.class);
		
		if (subject.getRank().ordinal() > creator.getRank().ordinal()) {
			return true;
		}
		return false;
	}

}
